package com.scy.controller;

import com.scy.pojo.TArticle;
import com.scy.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 司晨雨
 * @date 2020/6/19 20:13
 * @description
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @RequestMapping("/findArticleByPage")
    public String findArticleByPage(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum){
        int pageSize = 2;
        if (pageNum <= 0) {
            pageNum = 0;
        }
        Page<TArticle> articles = articleService.findAllByPage(pageNum,pageSize);
        int totalPages = articles.getTotalPages()-1;
        int totalPage = articles.getTotalPages();
        model.addAttribute("totalPage", totalPage);
        model.addAttribute("totalPages", totalPages);
        model.addAttribute("articles", articles);
        model.addAttribute("pageNum", pageNum);

        return  "client/index.html";
    }



}
